﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BF.IBLL.IXZCF_WS_AJYSSBLLLibrary;
using BF.Model;
using Base.Core.UnityFactory;
using BF.Infrastructure;
using System.Web.UI.HtmlControls;

namespace BF.Web.pages.XZCF_WS_AJYSSPage
{
    public partial class List : BasePage
    {
        #region 实例
        private readonly IXZCF_WS_AJYSSBLL ibll = IOCFactory.GetIOCResolve<IXZCF_WS_AJYSSBLL>();
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCotrol();
                BindList();
            }
        }

        private void BindList()
        {
			System.Linq.Expressions.Expression<Func<XZCF_WS_AJYSS, bool>> FuncWhere;
			FuncWhere = P => P.bDel != true;
			List<XZCF_WS_AJYSS> list = ibll.GetList(FuncWhere, P => new { P.gKey }, new PageModel(AspNetPager1.CurrentPageIndex), false);
			AspNetPager1.RecordCount = ibll.GetRowCount(FuncWhere);
			Repeater1.DataSource = list;
            Repeater1.DataBind();
        }

        private void BindCotrol()
        {
            //InitDLL(ddlScope,"WebNewClass");
        }

		//带请选择的 下拉列表
		private void InitDLL(DropDownList ddl, string strCode)
		{
			List<dic_Dict> modelList = GetDictList(strCode);
			ddl.AppendDataBoundItems = true;
			ddl.Items.Add(new ListItem("--请选择--", ""));
			for (int i = 0; i < modelList.Count; i++)
			{
				ddl.Items.Add(new ListItem(modelList[i].sName.ToString(), modelList[i].sCode.ToString()));
			}
		}

        protected void btnDelete_Click(object sender, EventArgs e)
        {
			bool flag = false;
			XZCF_WS_AJYSS model = new XZCF_WS_AJYSS();
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                HtmlInputCheckBox chk = (HtmlInputCheckBox)Repeater1.Items[i].FindControl("chksuserid");
                if (chk != null && chk.Checked)
                {
                    if (chk.Value != "")
                    {
                        Guid gkey = new Guid(chk.Value);
                        model = ibll.GetModel(P => P.gKey == gkey);
                        model.bDel = true;
                    }
                    if (ibll.Update())
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                Messages("删除成功！");
            }
            else
            {
                Messages("删除失败！");
            }
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }

		protected void btnQuery_Click(object sender, EventArgs e)
        {
		    BindList();
        }
    }
}
